package ru.averta.notes.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.averta.notes.dao.SiteDao;
import ru.averta.notes.dao.UrlDao;
import ru.averta.notes.domain.Site;
import ru.averta.notes.domain.Url;
import ru.averta.notes.service.SiteService;

import java.util.Date;

@Service
@Transactional
public class SiteServiceImpl extends UserableBusinessObjectService<Site, Long, SiteDao> implements SiteService {

    @Autowired private SiteDao dao;
    @Autowired private UrlDao urlDao;
 
    @Override 
    public Site create(Site newInstance) {
        newInstance.setLastModified(new Date());
        return super.create(newInstance);
    }

    @Override
    public Site findSiteByUrl(String url) {
        Url urlObject = urlDao.findUrlObjectByUrl(url);
        return (urlObject == null) ? null : dao.findSiteByUrl(urlObject);
    }
}
